package loader

import (
	"fmt"

	"github.com/yosuke-furukawa/json5/encoding/json5"
)

type Json5Coder struct{}

func (c *Json5Coder) Decode(b []byte, v map[string]any) error {
	if err := json5.Unmarshal(b, &v); nil != err {
		panic(fmt.Sprintf("ICL_ER.J5C_ER.D_DE.144004 解析配置文件失败: %v", err))
	}

	return nil
}

func (c *Json5Coder) Encode(v map[string]any) ([]byte, error) {
	b, err := json5.Marshal(v)
	if nil != err {
		panic(fmt.Sprintf("ICL_ER.J5C_ER.E_DE.233844 编码配置文件失败: %v", err))
	}

	return b, nil
}
